package com.mf.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.bo.ContractInfoBo;
import com.mf.entity.dto.roster.RosterDetailIdDto;
import com.mf.entity.vo.ContractInfoVo;
import com.mf.mapper.ContractInfoMapper;
import com.mf.service.IContractInfoService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.heollhai.common.utils.MybatisPlusUtils;
import io.github.heollhai.common.utils.VerifyUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*  服务实现类
*
* @author mf
* @since 2024-09-01
*/
@Service
public class ContractInfoServiceImpl extends ServiceImpl<ContractInfoMapper, ContractInfoBo> implements IContractInfoService {
    @Resource
    private ContractInfoMapper contractInfoMapper;

    @Override
    public Integer deleteById(RosterDetailIdDto rosterDetailIdDto) {
        return contractInfoMapper.deleteById(rosterDetailIdDto.getId());
    }

    /**
     * 新增|编辑
     */
    @Override
    public Integer insert(ContractInfoVo contractInfoVo) {
        final ContractInfoBo contractInfoBo = new ContractInfoBo();
        BeanUtils.copyProperties(contractInfoVo, contractInfoBo);
        if(VerifyUtils.isEmpty(contractInfoVo.getId())){
            return contractInfoMapper.insert(contractInfoBo);
        }

        return contractInfoMapper.updateById(contractInfoBo);
    }

    /**
     * 查询
     */
    @Override
    public List<ContractInfoVo> listByRosterId(Integer rosterId) {
        final LambdaQueryWrapper<ContractInfoBo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ContractInfoBo::getRosterId, rosterId);
        return MybatisPlusUtils.changeDataClass(contractInfoMapper.selectList(queryWrapper), ContractInfoVo.class);
    }
}
